<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的贷款申请记录</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            margin: 0;
            padding: 20px;
            min-height: 100vh;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            padding: 20px;
            background: white;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .header h1 {
            color: #333;
            margin: 0;
            font-size: 32px;
            font-weight: 300;
        }

        .header p {
            color: #666;
            margin: 10px 0 0;
            font-size: 18px;
        }

        .stats-cards {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
            flex-wrap: wrap;
        }

        .card {
            flex: 1;
            min-width: 200px;
            background: white;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            text-align: center;
            transition: transform 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
        }

        .card h3 {
            margin: 0 0 15px 0;
            color: #333;
            font-size: 20px;
        }

        .card .number {
            font-size: 36px;
            font-weight: bold;
            margin: 10px 0;
        }

        .pending .number {
            color: #ff9800;
        }

        .approved .number {
            color: #4CAF50;
        }

        .rejected .number {
            color: #f44336;
        }

        .total .number {
            color: #2196F3;
        }

        .content {
            background: white;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .content-header {
            padding: 25px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        .content-header h2 {
            margin: 0;
            font-weight: 300;
            font-size: 24px;
        }

        .new-loan-btn {
            background: #4CAF50;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            transition: all 0.3s ease;
        }

        .new-loan-btn:hover {
            background: #45a049;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .table-container {
            overflow-x: auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th {
            background-color: #f8f9fa;
            padding: 18px 15px;
            text-align: left;
            font-weight: 600;
            color: #333;
            border-bottom: 2px solid #e9ecef;
        }

        td {
            padding: 15px;
            border-bottom: 1px solid #e9ecef;
        }

        tr:hover {
            background-color: #f8f9fa;
        }

        .status-badge {
            padding: 6px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: bold;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }

        .status-approved {
            background-color: #d4edda;
            color: #155724;
        }

        .status-rejected {
            background-color: #f8d7da;
            color: #721c24;
        }

        .loan-image {
            max-width: 80px;
            max-height: 80px;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.2s;
        }

        .loan-image:hover {
            transform: scale(1.1);
        }

        .no-data {
            text-align: center;
            padding: 50px;
            color: #666;
        }

        .no-data i {
            font-size: 48px;
            margin-bottom: 20px;
            display: block;
            color: #ccc;
        }

        .actions {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }

        .action-btn {
            padding: 8px 16px;
            border-radius: 4px;
            text-decoration: none;
            font-size: 12px;
            font-weight: 500;
            transition: all 0.3s ease;
            border: none;
            cursor: pointer;
        }

        .detail-btn {
            background: #17a2b8;
            color: white;
        }

        .detail-btn:hover {
            background: #138496;
        }

        .pagination {
            padding: 20px;
            text-align: center;
            background: #f8f9fa;
        }

        .pagination a {
            display: inline-block;
            padding: 10px 15px;
            margin: 0 5px;
            background: white;
            color: #333;
            text-decoration: none;
            border-radius: 5px;
            border: 1px solid #ddd;
        }

        .pagination a:hover {
            background: #e9ecef;
        }

        .pagination .active {
            background: #007bff;
            color: white;
            border-color: #007bff;
        }

        .footer {
            text-align: center;
            margin-top: 30px;
            color: #666;
            font-size: 14px;
        }

        @media (max-width: 768px) {
            .stats-cards {
                flex-direction: column;
            }

            .content-header {
                flex-direction: column;
                text-align: center;
            }

            .header h1 {
                font-size: 24px;
            }

            .header p {
                font-size: 16px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>我的贷款申请记录</h1>
            <p>查看和管理您的所有贷款申请</p>
        </div>

        <!-- 统计卡片 -->
        <div class="stats-cards">
            <div class="card total">
                <h3>总申请数</h3>
                <div class="number" th:text="${loans.size()}">0</div>
                <p>所有贷款申请</p>
            </div>
            <div class="card pending">
                <h3>待审核</h3>
                <div class="number" th:text="${wsh.size()}">0</div>
                <p>等待处理</p>
            </div>
            <div class="card approved">
                <h3>已通过</h3>
                <div class="number" th:text="${ysh.size()}">0</div>
                <p>审核通过</p>
            </div>
            <div class="card rejected">
                <h3>已拒绝</h3>
                <div class="number" th:text="${yjj.size()}">0</div>
                <p>审核拒绝</p>
            </div>
        </div>

        <!-- 贷款列表 -->
        <div class="content">
            <div class="content-header">
                <h2>贷款申请详情</h2>
                <a href="/loan/toLoan" class="new-loan-btn">申请新贷款</a>
            </div>

            <div class="table-container">
                <table>
                    <thead>
                        <tr>
                            <th>申请编号</th>
                            <th>申请人</th>
                            <th>贷款金额</th>
                            <th>申请期限</th>
                            <th>申请时间</th>
                            <th>相关图片</th>
                            <th>状态</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="loan : ${loans}">
                            <td th:text="${loan.id}"></td>
                            <td th:text="${loan.userName}"></td>
                            <td th:text="${loan.price}"></td>
                            <td th:text="${loan.term}"></td>
                            <td th:text="${#dates.format(loan.createTime, 'yyyy-MM-dd HH:mm')}"></td>
                            <td>
                                <img th:if="${loan.img != null}"
                                     th:src="@{${loan.img}}"
                                     alt="贷款图片"
                                     class="loan-image"
                                     th:attr="data-src=@{${loan.img}}">
                                <span th:unless="${loan.img != null}">无图片</span>
                            </td>
                            <td>
                                <span th:if="${loan.status == 0}" class="status-badge status-pending">待审核</span>
                                <span th:if="${loan.status == 1}" class="status-badge status-approved">已通过</span>
                                <span th:if="${loan.status == 2}" class="status-badge status-rejected">已拒绝</span>
                            </td>

                        </tr>
                    </tbody>
                </table>

                <div class="no-data" th:if="${loans == null or #lists.isEmpty(loans)}">
                    <div>📋</div>
                    <h3>暂无贷款申请记录</h3>
                    <p>您还没有提交任何贷款申请</p>
                    <a href="/loan/toLoan" class="new-loan-btn" style="margin-top: 20px;">立即申请贷款</a>
                </div>
            </div>

            <!-- 分页 -->
            <div class="pagination" th:if="${totalPages > 1}">
                <a th:each="i : ${#numbers.sequence(1, totalPages)}"
                   th:href="@{/loan/list(page=${i})}"
                   th:class="${currentPage == i ? 'active' : ''}"
                   th:text="${i}">1</a>
            </div>
        </div>

        <div class="footer">
            <p>© 2023 贷款管理系统 | 为您提供专业的贷款服务</p>
        </div>
    </div>

    <!-- 图片放大模态框 -->
    <div id="imageModal" class="modal" style="display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.8);">
        <span class="close" style="position: absolute; top: 20px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; cursor: pointer; z-index: 1001;">&times;</span>
        <img class="modal-content" id="modalImage" style="position: relative; margin: auto; display: block; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 90%; max-height: 90%; border-radius: 8px;">
    </div>

    <script>
        // 图片放大功能
        document.addEventListener('DOMContentLoaded', function() {
            const images = document.querySelectorAll('.loan-image');
            const modal = document.getElementById("imageModal");
            const modalImg = document.getElementById("modalImage");
            const closeBtn = document.querySelector(".close");

            images.forEach(function(img) {
                img.addEventListener("click", function() {
                    modal.style.display = "block";
                    modalImg.src = this.getAttribute("data-src") || this.src;
                });
            });

            if (closeBtn) {
                closeBtn.onclick = function() {
                    modal.style.display = "none";
                };
            }

            modal.onclick = function(event) {
                if (event.target === modal) {
                    modal.style.display = "none";
                }
            };

            document.addEventListener("keydown", function(event) {
                if (event.key === "Escape" && modal.style.display === "block") {
                    modal.style.display = "none";
                }
            });
        });

        // 显示贷款详情
        function showLoanDetails(loanId) {
            alert('贷款详情功能待实现，贷款ID: ' + loanId);
            // 这里可以跳转到详情页面或显示模态框
        }
    </script>
</body>
</html>
